/*****************
* Ant Scriptdef/Frameworks/CSS/Blueprint routine for
* including blueprint framework into a project
*
* @version 0.1
* @author Arnoud ten Hoedt / Roonaan
*********************/
importClass(java.io.File);

var sSrc = "" + attributes.get("includesrc");
var sPlugins = "" + attributes.get("includeplugins");

var bIncludeSrc = sSrc.match(/yes|true|1/i);
var bIncludePlugins = sPlugins.match(/yes|true|1/i);

if(!getFrameworksCSSBlueprintToFolder(attributes.get("dir"), bIncludeSrc, bIncludePlugins)) {
	// Fail
}

function getFrameworksCSSBlueprintToFolder(dirName, includeSrc, includePlugins) {
	self.log("Validating that blueprint css framework has been downloaded");
	var dep = project.createTask("ant4web.dependencies");
	dep.setDynamicAttribute("dir", project.getProperty("ant4web.lib") + "/lib-ext/css/blueprint");
	dep.setDynamicAttribute("type", "http");
	dep.setDynamicAttribute("url", "http://github.com/joshuaclayton/blueprint-css/tarball/v0.9.1");
	dep.setDynamicAttribute("expand", "tgz");
	dep.setDynamicAttribute("expandbase", "joshuaclayton-blueprint-css-9be6857/blueprint");
	dep.perform();
	self.log("Blueprint CSS Framework downloaded");
	
	var dir = new File(dirName);
	if(!dir.exists() && !dir.mkdirs()) {
		self.log("Unable to create directory " + dir);
		return false;
	}
	
	var fs = project.createDataType("fileset");
	fs.setDir(new File(project.getProperty("ant4web.lib") + "/lib-ext/css/blueprint"));
	var excludes = ["ant.imported.log"];
	if(!includeSrc) {
		excludes.push("src");
		excludes.push("src/**/*");
		excludes.push("src/**/*.*");
	}
	if(!includePlugins) {
		excludes.push("plugins");
		excludes.push("plugins/**/*");
		excludes.push("plugins/**/*.*");
	}
	
	fs.setExcludes(excludes.join(" "));
	fs.setIncludes("**/*.*");
	var cp = project.createTask("copy");
	cp.setTodir(dir);
	cp.addFileset(fs);
	cp.perform();
	
	self.log("Blueprint files copied");
}

